package fag.core.model;

import java.awt.image.BufferedImage;
import java.io.Serializable;
import fag.core.collision.Hitbox;
import fag.core.geometry.Rectangle2D;
import fag.core.geometry.Vector2D;


public class Frame implements Serializable {

	Sprite sprite;
	Hitbox hitbox;
	int duration;
	Rectangle2D bounds;

	private static final long serialVersionUID = 1068367179650227646L;
	
	public Frame() {
		
		duration = 0;
		sprite = new Sprite();
		hitbox = null;
		bounds = null;
	
	}

	public Frame(int ms) {
		
		duration = ms;
		sprite = new Sprite();
		hitbox = null;
		bounds = null;
	}
	
	public Rectangle2D getBounds() {
		
		return bounds;
	}
	
	public Rectangle2D updateBounds() {
		
		if(bounds == null) {
			
			bounds = hitbox.getBounds();
		}
		return bounds;
	}
	
	public BufferedImage getBufferedImage() {
		
		return sprite.getBufferedImage();
	}
	
	public void setBufferedImage(BufferedImage i) {
		
		if(i == null) {
			
			sprite.serializableImage = new SerializableImage();
			sprite.bufferedImage = null;
			return; 
		}
		
		sprite.serializableImage = new SerializableImage(i);
	}
	
	public void setOffSet(Vector2D v) {
		
		sprite.offset = v;
	}

	public Vector2D getOffSet() {
		
		return sprite.offset;
	}

	public Hitbox getHitbox() {
		
		if(hitbox == null)
			return null;
		
		return hitbox.clone();
	}
	
	public void setHitbox(Hitbox h) {
		
		hitbox = h;
	}

	public int getDuration() {
		
		return duration;
	}

	public void setDuration(int i) {
		
		duration = i;
	}
	
	public int getWidth() {
		
		return sprite.getBufferedImage().getWidth();
	}
	
	public int getHeight() {
		
		return sprite.getBufferedImage().getHeight();
	}
	
	public Sprite getSprite() {
		
		return sprite;
	}

	public void setSprite(Sprite s) {
		
		sprite = s;
	}
}
